<template>
    <div class="content_base">
        <div class="upTo">
            <h2 class='title'>修改{{upTo.dikeName}}前期工作进度月报信息</h2>
            <el-form :model="upTo" ref="upTo"  label-position = 'right'  class="clearfix" :rules='rules' status-icon>
              <el-form-item label="圩堤名称：">
                <div class="wid">{{upTo.dikeName}}</div>
                </el-form-item>
              <el-form-item label="所在设区市：">
                <div class="wid">{{upTo.city}}</div>
              </el-form-item>
              <el-form-item label="属地：">
                <div class="wid">{{upTo.county}}</div> 
              </el-form-item>
              <el-form-item label="用地预审：" prop='landPreExam'>
                <el-input v-model.number="upTo.landPreExam"></el-input>
              </el-form-item>
              <el-form-item label="可研批复投资（万元）：" prop='permissibleInvest'>
                <el-input v-model.number="upTo.permissibleInvest" ></el-input>
              </el-form-item>
              <el-form-item label="初设批复治理长度（km）：" prop='initPermissiableLength'>
                <el-input v-model.number="upTo.initPermissiableLength" ></el-input>
              </el-form-item>
              <el-form-item label="初设批复投资（万元）：" prop='initPermissibleInvest'>
                <el-input v-model.number="upTo.initPermissibleInvest" ></el-input>
              </el-form-item>
              <el-form-item label="投标--分标段（个）：" prop="tenderCase">
                <el-input v-model.number="upTo.tenderCase" ></el-input>
              </el-form-item>
              <el-form-item label="投标--投标金额（万元）：" prop='tenderCapital' >
                <el-input v-model.number="upTo.tenderCapital" ></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="sureUpto('upTo')" >确认修改</el-button>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
              //上报的数据
          upTo:{
                dikeName:'', 
                city:'', 
                county:'',
                landPreExam: '',//用地预审
                permissibleInvest:'',//可批复投资
                initPermissiableLength:'',//可批复长度
                initPermissibleInvest:'',//初设可批复投资
                tenderCase:'',//分标段
                tenderCapital:'',//招标金额
                dikeCode:''
             },
          rules:{
                landPreExam: [{ required: true, trigger: 'blur',message:'请填写数据'}],//用地预审
                permissibleInvest:[{ type:'number',required: true, trigger: 'blur',message:'请填写数据'}],//可批复投资
                dikeCode: [{ type:'number',required: true, trigger: 'blur',message:'请填写数据'}],
                initPermissiableLength:[{ type:'number',required: true, trigger: 'blur',message:'请填写数据'}],//可批复长度
                initPermissibleInvest:[{ type:'number',required: true, trigger: 'blur',message:'请填写数据'}],//初设可批复投资
                tenderCase:[{ type:'number',required: true, trigger: 'blur',message:'请填写数据'}],//分标段
                tenderCapital:[{ type:'number',required: true, trigger: 'blur',message:'请填写数据'}],//招标金额
             },
           //本条数据的代码
          dikeCode:null,
        }
    },
    methods:{
       //获得三条基本的数据
         getBaseData(upTo){
            var _this = this ;
            var text = []
            var thisDate = (new Date()).getTime()
            this.$axios.get(`/dikeInfo/getdikeinfobycode/${this.dikeCode}`,{params:{
               thisDate:thisDate
             }}).then(function(res){
                  var data  = res.data.responseData
                  upTo.dikeName=data.dikeName
                  upTo.city=data.city
                  upTo.county=data.county  
            })
           
        },
        //确认上报点击事件
        sureUpto(upTo){
          var _this = this 
          this.$refs[upTo].validate((valid) => {
             if (valid) {
                    upTo = _this[upTo]
                   this.getData(upTo)
                   this.getNewData()
               } else {
               return false;
              }
           });
        },
        //确认上报---------发送请求
        getData(upTo){
          var _this = this
          upTo.dikeCode = this.dikeCode
           this.$axios.post(`/projectearly/updateproearlysameinfo/${this.dikeCode}`,upTo).then(function(res){
            var data = res.data.responseMessage
             if(data=='SUCCESS'){
              _this.$message({
                    message: '修改成功',
                    type: 'success'
                  });
                  _this.getNewData()
             _this.$router.push({name:'prejinzhang'})
              
            }else{
               _this.$message({
                    message: data
                  });
            }
          }).catch(function(err){
            console.log(err)
          })
        },
         //获得第一个月上报的数据
        getNewData(){
          var _this = this 
          var thisDate = (new Date()).getTime()
          this.$axios.get(`/dikeInfo/getfirstmonthinfo/PRE/${this.dikeCode}`,{params:{
              thisDate:thisDate
            }}).then(function(res){
             var codeMes = res.data.responseCode
             if(codeMes=='101'){
                     _this.$router.push({name:'login'})
               }else{
                 var data = res.data.responseData.data  
                 if(data){
                     for(var item in data){
                       _this.upTo[item] = data[item]?data[item]:0
                     }
                 }
                 _this.getBaseData(_this.upTo)
               }   
          })
          
        },
    },
    mounted(){
        var _this = this
        this.dikeCode = this.$route.params.dikeCode;
        //获得已经上报了的数据
        _this.getNewData()
    }
}
</script>

<style scoped>
   .clearfix:after{
        content: '';
        height: 0;
        clear: both;
        display: block;
   }
   .title{
       height: 100px;
       line-height: 100px;

   }
   .upTo{
       width: 90%;
       margin: 0 auto;
   }
   .upTo .el-form-item{
       width: 40%;
       float: left;
       margin-left:6%;
       /* min-width: 474px */
       position: relative;

   }
   .el-form-item .wid{
     /* width: 100px!important; */
     float: left!important;
     margin-left: 50px;
   }
   .el-input,.el-select{
       width:40%;
       position: absolute;
       left:250px;
       float: right;

   }
   .el-textarea{
     width: 40%;

   }
   .dialog-footer{
       height: 100px;
       line-height: 100px
   }
</style>